let prefixValue = "/jzweb/kawmType";
let configArr = {
    101:titleConfig,
    102:titleTexteConfig,
    201:loginLogoImageConfig,
    202:logoConfig,
    203:examinationLoginLogoImageConfig,
    204:examinationLogoImageConfig,
    205:iconConfig,
    301:loginImageConfig,
    302:examinationLoginImageConfig,
    303:examinationExcessiveImageConfig,
    401:examinationColorConfig,
    402:loginBtnColorConfig,
    403:examinationTextColor,
    501:themeColor
}

function cteated(value) {
    return new Promise(function (resolve, reject) {
        config(value).then((res) => {
            configArr[value](res.length !== 0 ? res[0]?.value : '')
            resolve(res[0]?.value)
        })

    })
}


//全局title配置
function titleConfig(value) {
    if(value === '') return
    $('title').html(value);
}

//后台logo配置
function logoConfig(value) {
    if(value === '') return
    let faviconElement = $('#backstageLogoImg');
    faviconElement.attr('src', `${value}`);
}


//登录页图片配置
function loginImageConfig(value) {
    if(value === '') return
    let faviconElement = $('#loginImageMain');
    faviconElement.css('background-image', 'url(' + `${value}` + ')');
}

//登录页logo图片配置
function loginLogoImageConfig(value) {
    if(value === '') return
    let faviconElement = $('#loginLogoImage');
    faviconElement.attr('src', `${value}`);
}

//考试页登录图片配置
function examinationLoginImageConfig(value) {
    if(value === '') return
    let faviconElement = $('#examinationLoginImage');
    faviconElement.css('background-image', 'url(' + `${value}` + ')');
}


//考试登录页logo图片配置
function examinationLoginLogoImageConfig(value) {
    if(value === '') return
    let faviconElement = $('#loginLogoImage');
    faviconElement.attr('src', `${value}`);
}

// 考试过渡页
function examinationExcessiveImageConfig(value) {
    if(value === '') return
    let faviconElement = $('#excessiveImage');
    faviconElement.css('background-image', 'url(' + `${value}` + ')');
}
//考试页logo图片配置
function examinationLogoImageConfig(value) {
    if(value === '') return
    let faviconElement = $('#examinationLogoImg');
    faviconElement.attr('src', `${value}`);
}

//页面icon配置
function iconConfig(value) {
    if(value === '') return
    let faviconLink = $('link[rel="shortcut icon"]');
    faviconLink.attr('href', `${value}`);
}

// 考试页文字标题
function titleTexteConfig(value) {
    if(value === '') return
    let faviconElement = $('#titleText');
    faviconElement.text(`${value}`);
}


//考试答题卡颜色配置
function examinationColorConfig(value) {
    if(value === '') return
    // 答题卡题目序号样式
    $('#answer li').css('border', `1px solid ${value}`);
    $('#choice li').css('border', `1px solid ${value}`);
    $('#questionsBox li').css('border', `1px solid ${value}`);
    $('#case li').css('border', `1px solid ${value}`);
    $('#nurse li').css('border', `1px solid ${value}`);
    $('#activity li').css('border', `1px solid ${value}`);

    // faviconElement文字
    $('#examinationColor a').css('color', value);

    // 已答题样式
    $('.hasBeenAnswer').css('background',value )
    $('<style>.hasBeenAnswer { background-color: ' + value + ' !important; }</style>').appendTo('head');
    $('.hasBeenAnswer').css('border',`1px solid ${value}`)
    $('.hasBeenAnswer a').css('color',`#ffffff`)
    // 题目序号样式
    let serial = $('.serial')

    // 答题卡已做区域样式
    let bgspan = $('.bgspan')
    bgspan.css('background',value)
    serial.css('background',value)

    // 答题卡hover样式
    $('.answerSheet li,#choice li,#case li,#questionsBox li,#nurse li,#activity li').hover(
        function() {
            $(this).css('background-color', value);
            $(this).css('background', value);
            $(this).children().css('color','#ffffff')
        },
        function() {
            $(this).css('background-color', '');
            $(this).css('background', '');
            $(this).children().css('color',value)
        }
    );

}

//登录按钮颜色配置
function loginBtnColorConfig(value) {
    if(value === '') return
    let faviconElement = $('#loginBtnColor');
    faviconElement.css('background', value);
}

//考试页文字颜色
function examinationTextColor(value) {
    let faviconElement = $('#eaxmName');
    let text = $('#titleText')
    let name = $('#name')
    let next = $('#next')
    name.css('color', value)
    next.css('color', value)
    text.css('color', value)
    faviconElement.css('color', value);
}

//主题颜色
function themeColor(value) {
    let arr = value
    return arr
}

function config (value) {
    return  new Promise((resolve, reject) => {
        try{
            $.ajax({
                url: prefixValue + '/list',
                data:{
                    pageNumber: 1,
                    pageSize: 10,
                    specificType:value
                },
                success: function(response) {
                    if(response.code === '0') {
                        resolve(response.data.records)
                        return
                    }
                    layer.msg(response.msg);
                },
                error: function(error) {
                    layer.msg(error);
                }
            });
        }catch (e) {
            layer.msg(e);
        }
    })
}

